// pages/person/person.js
var ajax = require("../../utils/network.js");
//获取应用实例
var app = getApp()
Page({
  data: {
    userInfo: {},
    circular: true,
    indicatordots: true,
    autoplay: true,
    interval: 3000,
    duration: 1000,
    banner: []
  },


  onLoad: function () {
    var that = this
    that.banner();
    //调用应用实例的方法获取全局数据
    app.getUserInfo(function (userInfo) {
      //更新数据
      that.setData({
        userInfo: userInfo
      })
    })
  },

  //轮播
  banner: function () {
    var that = this;
    var URL = ajax.server() + 'banner/info';
    var Params = {
      position: 'user_head'
    };
    var Method = 'GET';
    var Message = '正在加载数据';
    ajax.requestPost(URL, Params, Method, Message, function (res) {
      console.log('轮播图---', res)
      if (res.status == true) {
        let banner = res.data;
        that.setData({
          banner: banner
        })
      }
    }, function () {})
  },

  //监听轮播
  tapBanner: function(e){
    var that = this;
    var token = wx.getStorageSync("token");
    if (!token) {
      wx.navigateTo({
        url: '../login/login',
      })
    }
    else {
      var id = e.currentTarget.dataset.id;
      wx.navigateTo({
        url: '../single/single?id=' + id,
      })
    }
  },

  //个人信息
  person: function(){
    var that = this;
    var token = wx.getStorageSync("token");
    if (!token) {
      wx.navigateTo({
        url: '../login/login',
      })
    }
    else {
      wx.navigateTo({
        url: '../personDetail/personDetail',
      })
    }
  },

  //地址管理 
  address: function () {
    let that = this;
    let token = wx.getStorageSync("token");
    if (!token) {
      wx.navigateTo({
        url: '../login/login',
      })
    }
    else {
      wx.navigateTo({
        url: '../address/address',
      })
    }
  },

  //联系客服
  Tel: function(){
    wx.makePhoneCall({
      phoneNumber: '4008820010' //电话号码
    })
  },
  onShareAppMessage: function(){}
})
